﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using MINERP.BLL.CustomerManage;
using MINERP.COM;
using DevExpress.XtraGrid;

namespace MINERP.CustomerManage.Controller
{
    public class SearchController
    {
        /// <summary>
        /// 查询结果
        /// </summary>
        private List<OrderBagEntity>            _resultList = null;
        /// <summary>
        /// 订单处理
        /// </summary>
        private OrderBagManageBLL               _bagBLL = null;
        /// <summary>
        /// 生产流程处理
        /// </summary>
        private WorkOrderFlowListManageBLL      _flowBLL = new WorkOrderFlowListManageBLL();
            
        /// <summary>
        /// 查询显示GRID
        /// </summary>
        /// <param name="obj"></param>
        private GridControl                     _grid = null;
        /// <summary>
        /// 产品的所有类别信息

        /// </summary>
        private List<ProductCate>               _productcates = null;
        /// <summary>
        /// 所有用户信息

        /// </summary>
        private List<UserInfo>                  _userInfos = null;

        private List<ShopInfo>                  _shopInfoList = null;

        internal OrderBagController             _bagController = null;

        #region constructor

                internal SearchController(OrderBagController controller)
                {
                    this._bagBLL = controller._bll;
                    _bagController = controller;
                }

                internal GridControl Grid
                {
                    set
                    {
                        this._grid = value;
                    }
                }

        #endregion

        /// <summary>
        /// 产品类别
        /// </summary>
        internal List<ProductCate> Productcates
        {
            get
            {
                if (this._productcates == null)
                {
                    this._productcates = _bagBLL.GetAllProductCate();
                }

                return this._productcates;
            }
        }
        /// <summary>
        /// 用户信息
        /// </summary>
        internal List<UserInfo> UserInfos
        {
            get 
            {
                if (this._userInfos == null)
                {
                    this._userInfos = _flowBLL.GetUserInfo();
                }

                return this._userInfos;
            }
        }
        /// <summary>
        /// 商户基本信息
        /// </summary>
        internal List<ShopInfo> ShopInfoList
        {
            get
            {
                if (this._shopInfoList == null)
                {
                    this._shopInfoList = _bagBLL.GetAllShopInfo();
                }

                return this._shopInfoList;
            }
        }

       /// <summary>
       /// 产品信息
       /// </summary>
       /// <param name="cateid"></param>
       /// <returns></returns>
        internal List<Product> GetProductListByCate(int cateid)
        {
            return _bagBLL.GetProductByCate(cateid);
        }

        #region 查询
        /// <summary>
        /// 根据订单信息显示查询界面
        /// </summary>
        /// <param name="obj"></param>
        internal void Search(criteriaOrderBag obj)
        {
            _resultList = _bagBLL.GetListByComCondition(obj);
            this._grid.DataSource = _resultList;
            //_bagController.OrderBagCount = _resultList.Count;
            //标记为查询显示

            _bagController.IsSearchedResult = true;
            _bagController.ResultList = _resultList;
            if (_resultList != null)
                _bagController.OrderBagCount = _resultList.Count();
            else
                _bagController.OrderBagCount = 0;
            this._grid.RefreshDataSource();
        }

        /// <summary>
        /// 根据商户信息显示查询界面
        /// </summary>
        /// <param name="obj"></param>
        internal void Search(criteriaShop obj)
        {
            _resultList = _bagBLL.GetListByShopComCondition(obj);
            this._grid.DataSource = _resultList;
            //标记为查询显示

            _bagController.IsSearchedResult = true;
            _bagController.ResultList = _resultList;

            this._grid.RefreshDataSource();
        }
        /// <summary>
        /// 根据产品信息显示查询界面
        /// </summary>
        /// <param name="obj"></param>
        internal void Search(criteriaProductInfo obj)
        {
            _resultList = _bagBLL.GetListByProductInfoComCondition(obj);
            this._grid.DataSource = _resultList;
            //标记为查询显示

            _bagController.IsSearchedResult = true;
            _bagController.ResultList = _resultList;

            this._grid.RefreshDataSource();
        }

        /// <summary>
        /// 根据员工信息显示查询界面
        /// </summary>
        /// <param name="obj"></param>
        internal void Search(UserSearchInfo obj)
        {
            _resultList = _bagBLL.GetListByUserInfoComCondition(obj);
            this._grid.DataSource = _resultList;
            //标记为查询显示

            _bagController.IsSearchedResult = true;
            _bagController.ResultList = _resultList;

            this._grid.RefreshDataSource();
        }

        /// <summary>
        /// 按照片的备注进行查询
        /// </summary>
        /// <param name="photoRemark"></param>
        internal void Search(string photoRemark)
        {
            _resultList = _bagBLL.GetListByPhotoReamk(photoRemark);
            this._grid.DataSource = _resultList;
            //标记为查询显示

            _bagController.IsSearchedResult = true;
            _bagController.ResultList = _resultList;

            this._grid.RefreshDataSource();
        }

        #endregion
    }
}
